import { request } from "../request"
import qs from 'qs'
// 返回订单号
const getSubmitRequest = async (order) => {
  try {
    const res = await request({
      url: '/payment/submitOrder',
      method: 'post',
      data: {
        order
      }
    })
    return res
  } catch (error) {
    console.log(error);
  }
}

const payOrderRequest = async order => {
  try {
    const res = await request({
      url: '/payment/payOrder',
      method: 'post',
      data: {
        order: qs.stringify(order)
      }
    })
    return res
  } catch (error) {
    console.log(error);
  }
}

const payResultRequest = async (out_trade_no, trade_no) => {
  try {
    const res = await request({
      url: '/payment/queryPayResult',
      method: 'post',
      data: {
        out_trade_no,
        trade_no
      }
    })
    return res
  } catch (error) {
    console.log(error);
  }
}

export {
  getSubmitRequest,
  payOrderRequest,
  payResultRequest
}
